 script
#!/bin/sh

# Copyright (C) Iiheng

# 添加注释提高可读性
# 检查系统是基于Yum还是Apt，从而提高脚本的分发兼容性
if yum > /dev/null 2>&1; then
    package_manager=yum
elif apt-get > /dev/null 2>&1; then
    package_manager=apt-get
else
    echo "Error: Compatible package manager not found."
    exit 1
fi

# 使用变量简化后续修改
PKG1=pcre
PKG2=pcre-devel
PKG3=zlib
PKG4=zlib-devel

# 根据包管理器安装依赖
if [ "$package_manager" = "yum" ]; then
    # 在Red Hat基于的系统上使用Yum
    sudo yum install $PKG1 $PKG2 $PKG3 $PKG4 -y || { echo "Error installing packages with Yum."; exit 1; }
elif [ "$package_manager" = "apt-get" ]; then
    # 在Debian基于的系统上使用Apt-get
    sudo apt-get update || { echo "Error updating package lists."; exit 1; }
    sudo apt-get install $PKG1 $PKG2 $PKG3 $PKG4 -y || { echo "Error installing packages with Apt-get."; exit 1; }
fi

# 配置步骤，添加错误处理
echo "Configuring..."
./configure || { echo "Failed to configure. Aborting."; exit 1; }

# 编译步骤，添加错误处理
echo "Compiling..."
make || { echo "Failed to compile. Aborting."; exit 1; }

# 安装步骤，通常需要超级用户权限
# 提示：确保你了解安装目标以及它是否需要超级用户权限
echo "Installing..."
sudo make install || { echo "Failed to install. Aborting."; exit 1; }

echo "Process completed successfully."
